﻿using System;
using System.Collections.Generic;

namespace Utility
{
	// Token: 0x0200061C RID: 1564
	public class Enum<T> where T : struct
	{
		// Token: 0x06002591 RID: 9617 RVA: 0x001444B0 File Offset: 0x001426B0
		public static bool ContainsKey(string key)
		{
			foreach (string b in Enum.GetNames(typeof(T)))
			{
				if (key == b)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x06002592 RID: 9618 RVA: 0x001444F4 File Offset: 0x001426F4
		public static T Cast(string key, bool isErrorCheck = false)
		{
			if (isErrorCheck && !Enum<T>.ContainsKey(key))
			{
				global::Debug.LogError("enumの変換に失敗しました : " + key);
				return Enum<T>.Cast(int.MaxValue, false);
			}
			return (T)((object)Enum.Parse(typeof(T), key));
		}

		// Token: 0x06002593 RID: 9619 RVA: 0x00144544 File Offset: 0x00142744
		public static T Cast(int no, bool isErrorCheck = false)
		{
			Type typeFromHandle = typeof(T);
			if (isErrorCheck && !Enum.IsDefined(typeFromHandle, no))
			{
				global::Debug.LogError("enumの変換に失敗しました : " + no);
				no = int.MaxValue;
			}
			return (T)((object)Enum.ToObject(typeFromHandle, no));
		}

		// Token: 0x06002594 RID: 9620 RVA: 0x0014459C File Offset: 0x0014279C
		public static int Length()
		{
			return Enum.GetValues(typeof(T)).Length;
		}

		// Token: 0x06002595 RID: 9621 RVA: 0x001445B4 File Offset: 0x001427B4
		public static Enum<T>.EnumerateEnum Enumerate()
		{
			return new Enum<T>.EnumerateEnum();
		}

		// Token: 0x0200061D RID: 1565
		public class EnumerateEnum
		{
			// Token: 0x06002597 RID: 9623 RVA: 0x001445C4 File Offset: 0x001427C4
			public virtual IEnumerator<T> GetEnumerator()
			{
				foreach (object obj in Enum.GetValues(typeof(T)))
				{
					T e = (T)((object)obj);
					yield return e;
				}
				yield break;
			}
		}
	}
}
